using UnityEngine;

public class CameraFollow : MonoBehaviour
{
    public Transform target; // 玩家对象
    public float smoothSpeed = 0.125f;
    public Vector3 offset; // 摄像机相对于玩家的偏移量

    void LateUpdate()
    {
        if (target == null) return;

        Vector3 desiredPosition = target.position + offset;
        Vector3 smoothedPosition = Vector3.Lerp(transform.position, desiredPosition, smoothSpeed);
        transform.position = smoothedPosition;

        // 让摄像机始终看着玩家
        transform.LookAt(target);
    }
}